package cn.flant.db.hdle.dialect;

public class OracleDialect extends AnsiDialect {
	public static final String PAGED_ROWNUM = "ROWNUM_XXABC_XX";

	@Override
	public String buildPageSql(String selectSql, int pageSize, int pageNo) {
		int start = pageSize * (pageNo - 1);
		int end = start + pageSize;
		StringBuilder sb = new StringBuilder();
		sb.append("SELECT T.*");
		sb.append(" FROM (SELECT ROW_DATA.*, ROWNUM ").append(PAGED_ROWNUM);
		sb.append(" FROM (").append(selectSql).append(") ROW_DATA");
		sb.append(" WHERE ROWNUM <= ").append(end).append(") T");
		sb.append(" WHERE ").append(PAGED_ROWNUM).append(" > ").append(start);
		return sb.toString();
	}

	@Override
	public boolean isSupportAutoGenerateKey() {
		return false;
	}
}
